import { IsString, IsOptional, IsNumber, Min, Max, IsNotEmpty, IsIn } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

export class CreateMenuDto {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsString()
  @IsOptional()
  path?: string;

  @IsString()
  @IsOptional()
  component?: string;

  @IsString()
  @IsOptional()
  icon?: string;

  @IsNumber()
  @IsOptional()
  parentId?: number;

  @IsString()
  @IsIn(['menu', 'button'])
  type: string;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(1)
  visible?: number = 1;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(1)
  status?: number = 1;

  @IsNumber()
  @IsOptional()
  sort?: number = 0;

  @IsString()
  @IsOptional()
  remark?: string;
}

export class UpdateMenuDto {
  @IsString()
  @IsOptional()
  name?: string;

  @IsString()
  @IsOptional()
  path?: string;

  @IsString()
  @IsOptional()
  component?: string;

  @IsString()
  @IsOptional()
  icon?: string;

  @IsNumber()
  @IsOptional()
  parentId?: number;

  @IsString()
  @IsOptional()
  @IsIn(['menu', 'button'])
  type?: string;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(1)
  visible?: number;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(1)
  status?: number;

  @IsNumber()
  @IsOptional()
  sort?: number;

  @IsString()
  @IsOptional()
  remark?: string;
}

export class QueryMenusDto {
  @ApiProperty({ description: '页码', required: false, default: 1 })
  @IsOptional()
  @Type(() => Number)
  @Min(1)
  page?: number = 1;

  @ApiProperty({ description: '每页数量', required: false, default: 10 })
  @IsOptional()
  @Type(() => Number)
  @Min(1)
  @Max(100)
  pageSize?: number = 10;

  @ApiProperty({ description: '关键词搜索（菜单名、路径、备注）', required: false })
  @IsOptional()
  @IsString()
  keyword?: string;

  @ApiProperty({ description: '菜单名精确搜索', required: false })
  @IsOptional()
  @IsString()
  name?: string;

  @ApiProperty({ description: '菜单路径搜索', required: false })
  @IsOptional()
  @IsString()
  path?: string;

  @ApiProperty({ description: '菜单类型筛选', required: false, enum: ['menu', 'button'] })
  @IsOptional()
  @IsString()
  @IsIn(['menu', 'button'])
  type?: string;

  @ApiProperty({ description: '父菜单ID（0表示顶级菜单）', required: false })
  @IsOptional()
  @Type(() => Number)
  parentId?: number;

  @ApiProperty({ description: '显示状态：1-显示，0-隐藏', required: false })
  @IsOptional()
  @Type(() => Number)
  @Min(0)
  @Max(1)
  visible?: number;

  @ApiProperty({ description: '启用状态：1-启用，0-禁用', required: false })
  @IsOptional()
  @Type(() => Number)
  @Min(0)
  @Max(1)
  status?: number;

  @ApiProperty({ description: '创建时间开始（YYYY-MM-DD）', required: false })
  @IsOptional()
  @IsString()
  createTimeStart?: string;

  @ApiProperty({ description: '创建时间结束（YYYY-MM-DD）', required: false })
  @IsOptional()
  @IsString()
  createTimeEnd?: string;

  @ApiProperty({ description: '排序字段', required: false, enum: ['sort', 'createTime', 'updateTime', 'name'] })
  @IsOptional()
  @IsString()
  sortBy?: string;

  @ApiProperty({ description: '排序方向', required: false, enum: ['ASC', 'DESC'], default: 'DESC' })
  @IsOptional()
  @IsString()
  sortOrder?: 'ASC' | 'DESC' = 'DESC';
}